package com.qianfeng.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.qianfeng.dto.Page;
import com.qianfeng.entity.Doctor;
import com.qianfeng.mapper.DoctorMapper;
import com.qianfeng.service.DoctorService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
@Service
@Transactional
public class DoctorServiceImpl implements DoctorService {

    @Autowired
    private DoctorMapper doctorMapper;
    @Override
    public void addDoctor(Doctor doctor) {
        doctorMapper.addDoctor(doctor);
    }

    @Override
    public void updateDoctor(Doctor doctor) {
        doctorMapper.updateDoctor(doctor);
    }

    @Override
    public void deleteDoctor(Integer dId) {
        doctorMapper.deleteDoctor(dId);
    }

    @Override
    public Doctor getDoctorById(Integer dId) {
        return doctorMapper.getDoctorById(dId);
    }

    @Override
    public Page getDoctorPage(Integer pageNo, Integer pageSize) {
        Page page = new Page();
        PageHelper.startPage(pageNo, pageSize);
        List<Doctor> doctorList = doctorMapper.getDoctorList();
        PageInfo<Doctor> pageInfo = new PageInfo<>(doctorList);
        page.setObj(pageInfo.getList());
        page.setPageCount(pageInfo.getPages());
        page.setHasNext(pageInfo.isHasNextPage());
        return page;
    }

    @Override
    public List<Doctor> getDoctorList() {
        List<Doctor> doctorList = doctorMapper.getDoctorList();
        return doctorList;
    }
}
